package com.Jin.service;

import com.Jin.dao.CarPlateDao;
import com.Jin.pojo.CarPlate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
@Transactional
public class CarPlateServiceImpl implements CarPlateService{

    @Autowired
    CarPlateDao carPlateDao;

    //查询自己的车牌信息
    @Override
    public List<CarPlate> selectUserPlate(String account) {
        List<CarPlate> carPlateList = carPlateDao.selectUserPlate(account);
        return carPlateList;
    }

    //查询自己已拥有车牌
    @Override
    public List<CarPlate> selectHave(String account,String status) {
        List<CarPlate> carPlateList = carPlateDao.selectHave(account,status);
        return carPlateList;
    }

    //根据id查车牌
    @Override
    public CarPlate selectById(int id) {
        CarPlate carPlate = carPlateDao.selectById(id);
        return carPlate;
    }

    //查询所有车牌
    @Override
    public List<CarPlate> selectAllPlate() {
        List<CarPlate> carPlateList = carPlateDao.selectAllPlate();
        return carPlateList;
    }

    //查询特定状态的车牌
    @Override
    public List<CarPlate> selectPlateByStatus(String status) {
        List<CarPlate> carPlateList = carPlateDao.selectPlateByStatus(status);
        return carPlateList;
    }

    //申请、添加车牌
    @Override
    public boolean addPlate(CarPlate carPlate) {
        int  n = carPlateDao.addPlate(carPlate);
        return n>0;
    }

    //管理员更新车牌信息
    @Override
    public boolean updatePlate(CarPlate carPlate) {
        int n = carPlateDao.updatePlate(carPlate);
        return n>0;
    }

    //在用户更新信息后，更新owner,number
    @Override
    public boolean updateOwner(String account, String owner,String number) {
        int n = carPlateDao.updateOwner(account,owner,number);
        return n>0;
    }


    //删除车牌信息
    @Override
    public boolean deletePlate(int id) {
        int n = carPlateDao.deletePlate(id);
        return n>0;
    }

    //管理员处理申请
    @Override
    public boolean handleApply(int id, String status) {
        int n = carPlateDao.handleApply(id, status);
        return n>0;
    }
}
